package com.zykj.state;

import com.zykj.state.stateinfo.*;

/**
 * @author zhoulj(周利军) [1217102780@qq.com]
 * @Module ID:   <(模块)类编号，可以引用系统设计中的类编号>
 * @Comments: <对此类的描述，可以引用系统设计中的描述>
 * @JDK version used:      <JDK1.8> 21
 * @since 2019/1/8-16:21
 */
public class GumballMachine {

    /*public  final static int SOLD_OUT = 0;
    public final static int NO_QUARTER = 1;
    public final static int HAS_QUARTER = 2;
    public final static int SOLD = 3;

    int state = SOLD_OUT;
    int count = 0 ;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }*/

    // 糖果机 已投入钱的状态
    State hasQuarterState;

    //还没投入钱的状态
    State noQuarterState;
    //发放糖果状态
    State soldQuarterState;
    // 糖果售罄状态
    State soldOutuarterState;
    State winnerState;

    State state = soldOutuarterState;
    int count = 0 ;

    public GumballMachine(int numberGumballs) {
        hasQuarterState = new HasQuarterState(this);
        noQuarterState = new NoQuarterState(this);
        soldOutuarterState = new SoldOutState(this);
        soldQuarterState = new SoldState(this);
        winnerState = new WinnerState(this);
        if (numberGumballs > 0) {
            state = noQuarterState;
        }
        this.count = numberGumballs;
    }


    public void insertMoney() {
        state.insertMoney();
    }

    public void ejectMoney() {
        state.ejectMoney();
    }

    public void turnCrank() {
        state.turnCrank();
        state.dispense();
    }

    public void setState(State state) {
        this.state = state;
    }
    public void releaseBall() {
        System.out.println("发放糖果");
        if (count != 0) {
            count = count-1;
        }
    }

    public State getHasQuarterState() {
        return hasQuarterState;
    }

    public void setHasQuarterState(State hasQuarterState) {
        this.hasQuarterState = hasQuarterState;
    }

    public State getNoQuarterState() {
        return noQuarterState;
    }

    public void setNoQuarterState(State noQuarterState) {
        this.noQuarterState = noQuarterState;
    }

    public State getSoldQuarterState() {
        return soldQuarterState;
    }

    public void setSoldQuarterState(State soldQuarterState) {
        this.soldQuarterState = soldQuarterState;
    }

    public State getSoldOutuarterState() {
        return soldOutuarterState;
    }

    public void setSoldOutuarterState(State soldOutuarterState) {
        this.soldOutuarterState = soldOutuarterState;
    }

    public State getState() {
        return state;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public State getWinnerState() {
        return winnerState;
    }

    public void setWinnerState(State winnerState) {
        this.winnerState = winnerState;
    }
}
